﻿namespace WMS6.Web.Outbound
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoDetailServiceRef;
    using WMS6.Web.CommonMethodServiceRef;

    public class WaveSelection : BasePage
    {
        protected Button btnAdd;
        protected Button btnAdd3;
        protected Button btnAnalyse;
        protected Button btnCopy;
        protected Button btnDel;
        protected Button btnDel3;
        protected Button btnDelBrackets;
        protected Button btnDelete;
        protected Button btnGoBack;
        protected Button btnLeftBracketsAdd;
        protected Button btnNew;
        protected Button btnRightBracketsAdd;
        protected Button btnSave;
        protected DropDownList ddlAttribute;
        protected DropDownList ddlAttribute1;
        protected DropDownList ddlOperation;
        protected DropDownList ddlRecordType;
        protected DropDownList ddlTableName;
        protected HtmlForm F7171;
        protected HtmlInputHidden hdnFlag;
        protected HtmlInputHidden hdnFrom;
        protected HtmlHead Head1;
        protected Label lblAtrribute1;
        protected Label lblAttribute;
        protected Label lblDescr;
        protected Label lblFilterName;
        protected Label lbllocSelect;
        protected Label lblLocSelection2;
        protected Label lblMsg;
        protected Label lblOperation;
        protected Label lblOrderBy;
        protected Label lblOwner;
        protected Label lblRecordType;
        protected Label lblTableName;
        protected Label lblValue;
        protected Label lblWere;
        protected ListBox lbxOrder;
        protected ListBox lbxWhere;
        protected HtmlLink mycss;
        protected Label one1;
        protected Label one2;
        protected Button OrderByDown3;
        protected Button OrderByUp3;
        protected RadioButton rdobtnAnd;
        protected RadioButton rdobtnAsc;
        protected RadioButton rdobtndesc;
        protected ScriptManager ScriptManager1;
        protected RadioButton tdobtnOr;
        protected TextBox txtDescr;
        protected TextBox txtFilterName;
        protected TextBox txtValue;
        protected UpdatePanel up1;
        protected Button WhereDown;
        protected Button WhereUp;

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if ((this.ddlAttribute.SelectedValue != "0") && (!string.IsNullOrEmpty(this.txtValue.Text) || !this.txtValue.Enabled))
            {
                this.SelectCreate();
            }
            else
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2415_002");
                this.lblMsg.Visible = true;
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,3);</script>", false);
        }

        protected void btnAdd3_Click(object sender, EventArgs e)
        {
            if (this.ddlAttribute1.SelectedValue != "0")
            {
                this.OrderByCreate();
            }
            else
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2415_005");
                this.lblMsg.Visible = true;
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,3);</script>", false);
        }

        protected void btnAnalyse_Click(object sender, EventArgs e)
        {
            if (this.lbxWhere.Items.Count > 0)
            {
                FilterConfigHeaderInfo filterConfigInfo = null;
                string strFrom = string.Empty;
                string strWhere = string.Empty;
                string strOrderBy = string.Empty;
                string strSql = string.Empty;
                string strSelectValue = string.Empty;
                if (base.PageQueryEntityViewState is FilterConfigHeaderInfo)
                {
                    filterConfigInfo = base.PageQueryEntityViewState as FilterConfigHeaderInfo;
                    if (filterConfigInfo.FilterStatementInfos != null)
                    {
                        string CS00003;
                        foreach (FilterStatementInfo info in filterConfigInfo.FilterStatementInfos)
                        {
                            string strLeft = string.Empty;
                            string strRight = string.Empty;
                            for (int l = 0; info.LeftParen > l; l++)
                            {
                                strLeft = strLeft + "(";
                            }
                            for (int r = 0; info.RightParen > r; r++)
                            {
                                strRight = strRight + ")";
                            }
                            strFrom = strFrom.Replace(info.Attribute.Split(new char[] { '.' })[0] + ",", "");
                            strFrom = strFrom + info.Attribute.Split(new char[] { '.' })[0] + ",";
                            CS00003 = strWhere;
                            strWhere = CS00003 + strLeft + info.AndOr + "  " + info.Attribute + "  " + info.Operand + " " + info.LiteralValue + strRight + " ";
                        }
                        if (filterConfigInfo.FilterOrderByInfos != null)
                        {
                            foreach (FilterOrderByInfo info in filterConfigInfo.FilterOrderByInfos)
                            {
                                CS00003 = strOrderBy;
                                strOrderBy = CS00003 + info.Attribute + "  " + info.AscDesc + ",";
                                strSelectValue = strSelectValue + info.Attribute + ",";
                            }
                        }
                    }
                }
                if (!string.IsNullOrEmpty(strFrom))
                {
                    strFrom = strFrom.ToUpper().Substring(0, strFrom.Length - 1);
                }
                if (!string.IsNullOrEmpty(strOrderBy))
                {
                    strOrderBy = " ORDER BY  " + strOrderBy.ToUpper().Substring(0, strOrderBy.Length - 1);
                    strSelectValue = strSelectValue.ToUpper().Substring(0, strSelectValue.Length - 1);
                }
                else
                {
                    strSelectValue = "Count(*)";
                }
                strSql = "SELECT " + strSelectValue + " FROM  " + strFrom + "  WHERE  " + strWhere.ToUpper() + strOrderBy;
                this.lblMsg.Text = CommoneMethodServiceClientProxy.GetInstance().SqlAnalyse(strSql);
                if (string.IsNullOrEmpty(this.lblMsg.Text))
                {
                    this.lblMsg.Text = "筛选语句测试成功！";
                }
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,3);</script>", false);
        }

        protected void btnCopy_Click(object sender, EventArgs e)
        {
            this.txtFilterName.Text = string.Empty;
            this.txtFilterName.Enabled = true;
            this.hdnFlag.Value = "0";
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,3);</script>", false);
        }

        protected void btnDel_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.lbxWhere.SelectedValue))
            {
                string strselecttext = this.lbxWhere.SelectedItem.Text;
                this.SelectDelete();
                this.lblMsg.Text = strselecttext + base.GetGlobalMsgResource("C006");
            }
            else
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2415_003");
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,3);</script>", false);
        }

        protected void btnDel3_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.lbxOrder.SelectedValue))
            {
                string strselecttext = this.lbxOrder.SelectedItem.Text;
                this.OrderDelete();
                this.lblMsg.Text = strselecttext + base.GetGlobalMsgResource("C006");
            }
            else
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2415_003");
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,3);</script>", false);
        }

        protected void btnDelBrackets_Click(object sender, EventArgs e)
        {
            string strValue = string.Empty;
            if (!string.IsNullOrEmpty(this.lbxWhere.SelectedValue))
            {
                FilterConfigHeaderInfo filterConfigInfo = null;
                if (base.PageQueryEntityViewState is FilterConfigHeaderInfo)
                {
                    filterConfigInfo = base.PageQueryEntityViewState as FilterConfigHeaderInfo;
                    foreach (FilterStatementInfo info in filterConfigInfo.FilterStatementInfos)
                    {
                        strValue = info.AndOr + info.Attribute.Replace("@_@", "") + info.Operand + info.LiteralValue;
                        if (strValue == this.lbxWhere.SelectedValue)
                        {
                            if (info.RightParen > 0)
                            {
                                info.RightParen--;
                            }
                            else
                            {
                                info.LeftParen--;
                            }
                        }
                    }
                    this.lbxDatabind(filterConfigInfo);
                    base.PageQueryEntityViewState = filterConfigInfo;
                }
            }
            this.lbxWhere.SelectedValue = strValue;
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,3);</script>", false);
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if ((this.hdnFlag.Value == "1") && !(!(this.ddlRecordType.SelectedValue != "0") || string.IsNullOrEmpty(this.txtFilterName.Text)))
            {
                List<string> RecordType = new List<string>();
                List<string> FilterName = new List<string> {
                    this.ddlRecordType.SelectedValue,
                    this.txtFilterName.Text
                };
                this.lblMsg.Text = BaseInfoDetailServiceClientProxy.GetInstance().DeleteDetail(RecordType, FilterName, new List<string>(), "FILTER_CONFIG_DETAIL") + " 删除成功!";
            }
        }

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            switch (this.hdnFrom.Value)
            {
                case "query":
                    base.Response.Redirect("WaveSelectionQuery.aspx", false);
                    break;

                case "list":
                    base.Response.Redirect("WaveSelectionList.aspx?from=edit", false);
                    break;
            }
        }

        protected void btnLeftBracketsAdd_Click(object sender, EventArgs e)
        {
            string strValue = string.Empty;
            if (!string.IsNullOrEmpty(this.lbxWhere.SelectedValue))
            {
                FilterConfigHeaderInfo filterConfigInfo = null;
                if (base.PageQueryEntityViewState is FilterConfigHeaderInfo)
                {
                    filterConfigInfo = base.PageQueryEntityViewState as FilterConfigHeaderInfo;
                    foreach (FilterStatementInfo info in filterConfigInfo.FilterStatementInfos)
                    {
                        strValue = info.AndOr + info.Attribute.Replace("@_@", "") + info.Operand + info.LiteralValue;
                        if (strValue == this.lbxWhere.SelectedValue)
                        {
                            info.LeftParen++;
                            break;
                        }
                    }
                    this.lbxDatabind(filterConfigInfo);
                    base.PageQueryEntityViewState = filterConfigInfo;
                }
            }
            this.lbxWhere.SelectedValue = strValue;
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,3);</script>", false);
        }

        protected void btnRightBracketsAdd_Click(object sender, EventArgs e)
        {
            string strValue = string.Empty;
            if (!string.IsNullOrEmpty(this.lbxWhere.SelectedValue))
            {
                FilterConfigHeaderInfo filterConfigInfo = null;
                if (base.PageQueryEntityViewState is FilterConfigHeaderInfo)
                {
                    filterConfigInfo = base.PageQueryEntityViewState as FilterConfigHeaderInfo;
                    foreach (FilterStatementInfo info in filterConfigInfo.FilterStatementInfos)
                    {
                        strValue = info.AndOr + info.Attribute.Replace("@_@", "") + info.Operand + info.LiteralValue;
                        if (strValue == this.lbxWhere.SelectedValue)
                        {
                            info.RightParen++;
                            break;
                        }
                    }
                    this.lbxDatabind(filterConfigInfo);
                    base.PageQueryEntityViewState = filterConfigInfo;
                }
            }
            this.lbxWhere.SelectedValue = strValue;
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,3);</script>", false);
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtFilterName.Text))
            {
                this.lblMsg.Text = "请输入筛选名称！";
                this.lblMsg.Visible = true;
                this.txtFilterName.Focus();
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,3);</script>", false);
            }
            else if (this.ddlRecordType.SelectedValue == "0")
            {
                this.lblMsg.Text = "请选择筛选类型！";
                this.lblMsg.Visible = true;
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,3);</script>", false);
            }
            else
            {
                FilterConfigHeaderInfo filterConfigInfo = new FilterConfigHeaderInfo();
                if (base.PageQueryEntityViewState is FilterConfigHeaderInfo)
                {
                    filterConfigInfo = base.PageQueryEntityViewState as FilterConfigHeaderInfo;
                    FilterConfigDetailInfo FilterConfigDetail = new FilterConfigDetailInfo {
                        RecordType = this.ddlRecordType.SelectedValue,
                        Descr = this.txtDescr.Text,
                        FilterName = this.txtFilterName.Text,
                        FilterStatement = this.lblWere.Text
                    };
                    string orderBy = string.IsNullOrEmpty(this.lblOrderBy.Text.Trim()) ? "" : ("  ORDER BY " + this.lblOrderBy.Text);
                    FilterConfigDetail.FilterStatement = FilterConfigDetail.FilterStatement + orderBy;
                    filterConfigInfo.FilterConfigDetailInfos = FilterConfigDetail;
                    if (filterConfigInfo.FilterOrderByInfos == null)
                    {
                        filterConfigInfo.FilterOrderByInfos = new List<FilterOrderByInfo>();
                    }
                    if (filterConfigInfo.FilterStatementInfos == null)
                    {
                        filterConfigInfo.FilterStatementInfos = new List<FilterStatementInfo>();
                    }
                }
                if (this.hdnFlag.Value == "1")
                {
                    filterConfigInfo.UpdatedBy = base.UserInfo.UserID;
                    this.UpdateLocSelectInfo(filterConfigInfo);
                }
                else
                {
                    filterConfigInfo.CreatedBy = base.UserInfo.UserID;
                    this.InsertLocSelectInfo(filterConfigInfo);
                }
            }
        }

        public void ddlAttribute_SelectedIndexChanged(object sender, EventArgs e)
        {
            List<FieldNameInfo> fieldNameInfoList = base.PageQueryEntitySession as List<FieldNameInfo>;
            foreach (FieldNameInfo info in fieldNameInfoList)
            {
                if (info.Name == this.ddlAttribute.SelectedValue)
                {
                    this.txtValue.MaxLength = int.Parse(info.Length);
                    this.txtValue.Attributes.Add("onblur", this.FunctionMatchingByTableType(info.Type));
                }
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,3);</script>", false);
        }

        protected void ddlOperation_SelectedIndexChanged(object sender, EventArgs e)
        {
            string CS40000 = this.ddlOperation.SelectedValue;
            if ((CS40000 != null) && ((CS40000 == "IS NOT NULL") || (CS40000 == "IS NULL")))
            {
                this.txtValue.Text = "";
                this.txtValue.Enabled = false;
            }
            else
            {
                this.txtValue.Enabled = true;
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,3);</script>", false);
        }

        protected void ddlRecordType_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.ddlRecordType.SelectedValue != "0")
            {
                FilterConfigHeaderInfo FilterConfigHeader = BaseInfoDetailServiceClientProxy.GetInstance().GetDetailInfoByID(this.ddlRecordType.SelectedValue, this.txtFilterName.Text, "", "FILTER_CONFIG_DETAIL") as FilterConfigHeaderInfo;
                this.ddlTableNameDataBind(FilterConfigHeader);
                base.PageQueryEntityViewState = FilterConfigHeader;
            }
            else
            {
                this.ddlTableName.Items.Clear();
                this.ddlTableName.Items.Add(new ListItem("-----", "0", true));
                this.ddlAttribute.Items.Clear();
                this.ddlAttribute.Items.Add(new ListItem("-----", "0", true));
            }
        }

        protected void ddlTableName_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.ddlTableName.SelectedValue != "0")
            {
                List<FieldNameInfo> fieldNameInfo = CommoneMethodServiceClientProxy.GetInstance().GetFieldNameByTableName(this.ddlTableName.SelectedValue);
                if (fieldNameInfo != null)
                {
                    this.ddlAttribute1.Items.Clear();
                    this.ddlAttribute1.Items.Add(new ListItem("-----", "0", true));
                    this.ddlAttribute.Items.Clear();
                    this.ddlAttribute.Items.Add(new ListItem("-----", "0", true));
                    foreach (FieldNameInfo info in fieldNameInfo)
                    {
                        ListItem listitem = new ListItem {
                            Text = info.Name,
                            Value = info.Name
                        };
                        this.ddlAttribute.Items.Add(listitem);
                        this.ddlAttribute1.Items.Add(listitem);
                    }
                }
                else
                {
                    this.ddlAttribute.Items.Clear();
                    this.ddlAttribute.Items.Add(new ListItem("没有可用数据源", "0"));
                    this.ddlAttribute1.Items.Clear();
                    this.ddlAttribute1.Items.Add(new ListItem("没有可用数据源", "0"));
                }
                base.PageQueryEntitySession = fieldNameInfo;
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,3);</script>", false);
            }
        }

        private void ddlTableNameDataBind(FilterConfigHeaderInfo FilterConfigHeader)
        {
            if (FilterConfigHeader != null)
            {
                if (!string.IsNullOrEmpty(FilterConfigHeader.TableName))
                {
                    this.ddlTableName.Items.Clear();
                    this.ddlTableName.Items.Add(new ListItem("-----", "0", true));
                    string[] strTable = FilterConfigHeader.TableName.Split(new char[] { ',' });
                    for (int i = 0; strTable.Count<string>() > i; i++)
                    {
                        ListItem listItem = new ListItem {
                            Text = strTable[i].ToUpper(),
                            Value = strTable[i].ToUpper()
                        };
                        this.ddlTableName.Items.Add(listItem);
                    }
                }
                else
                {
                    this.ddlTableName.Items.Clear();
                    this.ddlTableName.Items.Add(new ListItem("没有可用数据源", "0"));
                }
            }
        }

        private void DropDownListDataBind()
        {
            DataSet ds = null;
            ds = BaseInfoServiceClientProxy.GetInstance().GetAllInfo("FILTER_CONFIG_HEADER");
            if ((ds != null) && (ds.Tables[0].Rows.Count > 0))
            {
                this.ddlRecordType.Items.Clear();
                this.ddlRecordType.Items.Add(new ListItem("-----", "0", true));
                for (int i = 0; ds.Tables[0].Rows.Count > i; i++)
                {
                    ListItem listItem = new ListItem();
                    if (ds.Tables[0].Rows[i]["RECORD_TYPE"].ToString() == "WaveSel")
                    {
                        listItem.Selected = true;
                    }
                    listItem.Text = ds.Tables[0].Rows[i]["RECORD_TYPE"].ToString();
                    listItem.Value = ds.Tables[0].Rows[i]["RECORD_TYPE"].ToString();
                    this.ddlRecordType.Items.Add(listItem);
                }
                this.ddlRecordType_OnSelectedIndexChanged(null, null);
            }
        }

        private string FunctionMatchingByTableType(string Type)
        {
            switch (Type.ToUpper())
            {
                case "BIGINT":
                case "INT":
                case "SMALLINT":
                case "tinyint ":
                    return "dataVer._Is123(this,'lblMsg')";

                case "DECIMAL":
                case "MONEY":
                case "SMALLMONEY":
                case "FLOAT":
                case "REAL":
                    return "dataVer._Is123x(this,'lblMsg')";

                case "DATETIME":
                case "SMALLDATETIME":
                    return "dataVer._IsTime(this,'lblMsg')";
            }
            return "";
        }

        private void InsertLocSelectInfo(FilterConfigHeaderInfo filterConfigInfo)
        {
            try
            {
                this.lblMsg.Text = BaseInfoDetailServiceClientProxy.GetInstance().InsertDetail(filterConfigInfo, "FILTER_CONFIG_DETAIL") + " 保存成功!";
                this.hdnFlag.Value = "1";
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
        }

        private void lbxDatabind(FilterConfigHeaderInfo filterConfigInfo)
        {
            if (filterConfigInfo != null)
            {
                this.lbxWhere.Items.Clear();
                string strWhere = string.Empty;
                foreach (FilterStatementInfo info in filterConfigInfo.FilterStatementInfos)
                {
                    ListItem listItem = new ListItem();
                    string strLeft = string.Empty;
                    string strRight = string.Empty;
                    for (int l = 0; info.LeftParen > l; l++)
                    {
                        strLeft = strLeft + "(";
                    }
                    for (int r = 0; info.RightParen > r; r++)
                    {
                        strRight = strRight + ")";
                    }
                    string CS00002 = strWhere;
                    strWhere = CS00002 + strLeft + info.AndOr + "  " + info.Attribute.Replace("@_@", "") + "  " + info.Operand + " " + info.LiteralValue + strRight + " ";
                    listItem.Text = strLeft + info.AndOr + " " + info.Attribute.Replace("@_@", "") + "  " + info.Operand + " " + info.LiteralValue + strRight;
                    listItem.Value = info.AndOr + info.Attribute.Replace("@_@", "") + info.Operand + info.LiteralValue;
                    this.lbxWhere.Items.Add(listItem);
                }
                this.lblWere.Text = strWhere;
            }
        }

        private void lbxOrderDatabind(FilterConfigHeaderInfo filterConfigInfo)
        {
            if (filterConfigInfo != null)
            {
                this.lbxOrder.Items.Clear();
                string strOrderBy = string.Empty;
                foreach (FilterOrderByInfo info in filterConfigInfo.FilterOrderByInfos)
                {
                    ListItem listItem = new ListItem();
                    string CS00002 = strOrderBy;
                    strOrderBy = CS00002 + info.Attribute.Replace("@_@", "") + " " + info.AscDesc + ",";
                    listItem.Text = info.Attribute.Replace("@_@", "") + "　　　　　　　　　　　" + info.AscDesc;
                    listItem.Value = info.Attribute.Replace("@_@", "") + info.AscDesc;
                    this.lbxOrder.Items.Add(listItem);
                }
                if (!string.IsNullOrEmpty(strOrderBy))
                {
                    this.lblOrderBy.Text = strOrderBy.Substring(0, strOrderBy.Length - 1);
                }
            }
        }

        private void LoadData()
        {
            try
            {
                this.hdnFrom.Value = base.Request.QueryString["from"];
                FilterConfigHeaderInfo FilterConfigHeader = null;
                if (!string.IsNullOrEmpty(base.Request.QueryString["Type"]))
                {
                    this.hdnFlag.Value = base.Request.QueryString["Type"];
                    this.txtFilterName.Text = base.Request.QueryString["FilterName"];
                    if (this.hdnFlag.Value == "1")
                    {
                        this.ddlRecordType.SelectedValue = base.Request.QueryString["RecordType"];
                        FilterConfigHeader = BaseInfoDetailServiceClientProxy.GetInstance().GetDetailInfoByID(this.ddlRecordType.SelectedValue, this.txtFilterName.Text, "", "FILTER_CONFIG_DETAIL") as FilterConfigHeaderInfo;
                        this.txtFilterName.Enabled = false;
                        this.txtDescr.Text = FilterConfigHeader.FilterConfigDetailInfos.Descr;
                        this.lbxDatabind(FilterConfigHeader);
                        this.lbxOrderDatabind(FilterConfigHeader);
                        this.ddlTableNameDataBind(FilterConfigHeader);
                        base.PageQueryEntityViewState = FilterConfigHeader;
                    }
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2415_001") + ex.Message;
                this.lblMsg.Visible = true;
            }
        }

        private void OrderByCreate()
        {
            FilterConfigHeaderInfo filterConfigInfo = null;
            if (base.PageQueryEntityViewState is FilterConfigHeaderInfo)
            {
                filterConfigInfo = base.PageQueryEntityViewState as FilterConfigHeaderInfo;
                if (filterConfigInfo.FilterOrderByInfos == null)
                {
                    filterConfigInfo.FilterOrderByInfos = new List<FilterOrderByInfo>();
                }
                FilterOrderByInfo filterOrderBy = new FilterOrderByInfo();
                string strTable = this.ddlTableName.SelectedValue.ToUpper();
                filterOrderBy.FilterName = this.txtFilterName.Text;
                filterOrderBy.AscDesc = this.rdobtnAsc.Checked ? "ASC" : "DESC";
                filterOrderBy.RecordType = filterConfigInfo.RecordType;
                filterOrderBy.FilterName = filterConfigInfo.TableName;
                filterOrderBy.Attribute = "@_@" + strTable + "." + this.ddlAttribute1.SelectedValue.ToUpper();
                filterConfigInfo.FilterOrderByInfos.Add(filterOrderBy);
                base.PageQueryEntityViewState = filterConfigInfo;
                this.lbxOrderDatabind(filterConfigInfo);
            }
        }

        protected void OrderByDown3_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.lbxOrder.SelectedValue))
            {
                FilterConfigHeaderInfo filterConfigInfo = null;
                if (base.PageQueryEntityViewState is FilterConfigHeaderInfo)
                {
                    filterConfigInfo = base.PageQueryEntityViewState as FilterConfigHeaderInfo;
                    List<FilterOrderByInfo> OrderBy = filterConfigInfo.FilterOrderByInfos;
                    for (int i = 0; OrderBy.Count > i; i++)
                    {
                        if ((OrderBy[i].Attribute.Replace("@_@", "") + OrderBy[i].AscDesc) == this.lbxOrder.SelectedValue)
                        {
                            if (i < (OrderBy.Count - 1))
                            {
                                FilterOrderByInfo FilterOrderBy = OrderBy[i];
                                filterConfigInfo.FilterOrderByInfos.RemoveAt(i);
                                filterConfigInfo.FilterOrderByInfos.Insert(i + 1, FilterOrderBy);
                                break;
                            }
                            this.lblMsg.Text = base.GetGlobalMsgResource("F2415_004");
                            this.lblMsg.Visible = true;
                        }
                    }
                    this.lbxOrderDatabind(filterConfigInfo);
                    base.PageQueryEntityViewState = filterConfigInfo;
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,3);</script>", false);
                }
            }
        }

        protected void OrderByUp3_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.lbxOrder.SelectedValue))
            {
                FilterConfigHeaderInfo filterConfigInfo = null;
                if (base.PageQueryEntityViewState is FilterConfigHeaderInfo)
                {
                    filterConfigInfo = base.PageQueryEntityViewState as FilterConfigHeaderInfo;
                    List<FilterOrderByInfo> OrderBy = filterConfigInfo.FilterOrderByInfos;
                    for (int i = 0; OrderBy.Count > i; i++)
                    {
                        if ((OrderBy[i].Attribute.Replace("@_@", "") + OrderBy[i].AscDesc) == this.lbxOrder.SelectedValue)
                        {
                            if (i > 0)
                            {
                                FilterOrderByInfo FilterOrderBy = OrderBy[i];
                                filterConfigInfo.FilterOrderByInfos.RemoveAt(i);
                                filterConfigInfo.FilterOrderByInfos.Insert(i - 1, FilterOrderBy);
                                break;
                            }
                            this.lblMsg.Text = base.GetGlobalMsgResource("F2415_006");
                            this.lblMsg.Visible = true;
                        }
                    }
                    this.lbxOrderDatabind(filterConfigInfo);
                    base.PageQueryEntityViewState = filterConfigInfo;
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,3);</script>", false);
                }
            }
        }

        private void OrderDelete()
        {
            FilterConfigHeaderInfo filterConfigInfo = null;
            if (base.PageQueryEntityViewState is FilterConfigHeaderInfo)
            {
                filterConfigInfo = base.PageQueryEntityViewState as FilterConfigHeaderInfo;
                foreach (FilterOrderByInfo info in filterConfigInfo.FilterOrderByInfos)
                {
                    if ((info.Attribute.Replace("@_@", "") + info.AscDesc) == this.lbxOrder.SelectedValue)
                    {
                        filterConfigInfo.FilterOrderByInfos.Remove(info);
                        break;
                    }
                }
                base.PageQueryEntityViewState = filterConfigInfo;
                this.lbxOrderDatabind(filterConfigInfo);
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,3);</script>", false);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.lblMsg.Text = "";
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.DropDownListDataBind();
                this.LoadData();
            }
        }

        private void SelectCreate()
        {
            FilterConfigHeaderInfo filterConfigInfo = null;
            if (base.PageQueryEntityViewState is FilterConfigHeaderInfo)
            {
                string strTable;
                filterConfigInfo = base.PageQueryEntityViewState as FilterConfigHeaderInfo;
                if (filterConfigInfo.FilterStatementInfos == null)
                {
                    filterConfigInfo.FilterStatementInfos = new List<FilterStatementInfo>();
                }
                FilterStatementInfo filterStatement = new FilterStatementInfo();
                if (this.lbxWhere.Items.Count > 0)
                {
                    filterStatement.AndOr = this.rdobtnAnd.Checked ? "AND" : "OR";
                }
                if (this.ddlTableName.SelectedValue.ToUpper().ToUpper() == "ORDERS")
                {
                    strTable = "O";
                }
                else
                {
                    strTable = "OD";
                }
                filterStatement.FilterName = this.txtFilterName.Text;
                filterStatement.Attribute = "@_@" + strTable + "." + this.ddlAttribute.SelectedValue.ToUpper();
                filterStatement.Operand = this.ddlOperation.SelectedValue.ToUpper();
                if (!string.IsNullOrEmpty(this.txtValue.Text))
                {
                    filterStatement.LiteralValue = "'" + this.txtValue.Text.ToUpper() + "'";
                }
                filterConfigInfo.FilterStatementInfos.Add(filterStatement);
                base.PageQueryEntityViewState = filterConfigInfo;
                this.lbxDatabind(filterConfigInfo);
            }
        }

        private void SelectDelete()
        {
            FilterConfigHeaderInfo filterConfigInfo = null;
            if (base.PageQueryEntityViewState is FilterConfigHeaderInfo)
            {
                filterConfigInfo = base.PageQueryEntityViewState as FilterConfigHeaderInfo;
                foreach (FilterStatementInfo info in filterConfigInfo.FilterStatementInfos)
                {
                    if ((info.AndOr + info.Attribute.Replace("@_@", "") + info.Operand + info.LiteralValue) == this.lbxWhere.SelectedValue)
                    {
                        filterConfigInfo.FilterStatementInfos.Remove(info);
                        break;
                    }
                }
                this.lbxDatabind(filterConfigInfo);
                base.PageQueryEntityViewState = filterConfigInfo;
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,3);</script>", false);
            }
        }

        private void UpdateLocSelectInfo(FilterConfigHeaderInfo filterConfigInfo)
        {
            try
            {
                this.lblMsg.Text = BaseInfoDetailServiceClientProxy.GetInstance().UpdateDetail(filterConfigInfo, "FILTER_CONFIG_DETAIL") + " 更新成功!";
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
        }

        protected void WhereDown_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.lbxWhere.SelectedValue))
            {
                FilterConfigHeaderInfo filterConfigInfo = null;
                if (base.PageQueryEntityViewState is FilterConfigHeaderInfo)
                {
                    filterConfigInfo = base.PageQueryEntityViewState as FilterConfigHeaderInfo;
                    List<FilterStatementInfo> Statement = filterConfigInfo.FilterStatementInfos;
                    for (int i = 0; Statement.Count > i; i++)
                    {
                        if ((Statement[i].AndOr + Statement[i].Attribute.Replace("@_@", "") + Statement[i].Operand + Statement[i].LiteralValue) == this.lbxWhere.SelectedValue)
                        {
                            if (i < (Statement.Count - 1))
                            {
                                FilterStatementInfo FilterStatement = Statement[i];
                                if (i == 0)
                                {
                                    FilterStatement.AndOr = Statement[i + 1].AndOr;
                                    Statement[i + 1].AndOr = "";
                                }
                                filterConfigInfo.FilterStatementInfos.RemoveAt(i);
                                filterConfigInfo.FilterStatementInfos.Insert(i + 1, FilterStatement);
                                break;
                            }
                            this.lblMsg.Text = base.GetGlobalMsgResource("F2415_004");
                            this.lblMsg.Visible = true;
                        }
                    }
                    this.lbxDatabind(filterConfigInfo);
                    base.PageQueryEntityViewState = filterConfigInfo;
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,3);</script>", false);
                }
            }
        }

        protected void WhereUp_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.lbxWhere.SelectedValue))
            {
                FilterConfigHeaderInfo filterConfigInfo = null;
                if (base.PageQueryEntityViewState is FilterConfigHeaderInfo)
                {
                    filterConfigInfo = base.PageQueryEntityViewState as FilterConfigHeaderInfo;
                    List<FilterStatementInfo> Statement = filterConfigInfo.FilterStatementInfos;
                    for (int i = 0; Statement.Count > i; i++)
                    {
                        if ((Statement[i].AndOr + Statement[i].Attribute.Replace("@_@", "") + Statement[i].Operand + Statement[i].LiteralValue) == this.lbxWhere.SelectedValue)
                        {
                            if (i > 0)
                            {
                                FilterStatementInfo FilterStatement = Statement[i];
                                if (i == 1)
                                {
                                    Statement[i - 1].AndOr = FilterStatement.AndOr;
                                    FilterStatement.AndOr = "";
                                }
                                filterConfigInfo.FilterStatementInfos.RemoveAt(i);
                                filterConfigInfo.FilterStatementInfos.Insert(i - 1, FilterStatement);
                                break;
                            }
                            this.lblMsg.Text = base.GetGlobalMsgResource("F2415_006");
                            this.lblMsg.Visible = true;
                        }
                    }
                    this.lbxDatabind(filterConfigInfo);
                    base.PageQueryEntityViewState = filterConfigInfo;
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,3);</script>", false);
                }
            }
        }
    }
}

